/**   
 * Copyright © 2018 eSunny Info. Tech Ltd. All rights reserved.
 * 
 * @Package: com.wxsoft.java.classload.demo 
 * @author: chenliang   
 * @date: 2018年6月22日 下午8:04:17 
 */
package com.wxsoft.java.classload.demo;

/**
 * @author chenliang
 *
 */
public class ClassLoaderTest2 {
	public static void main(String[] args) throws ClassNotFoundException {

//		String rootDir = "/Users/zejian/Downloads/Java8_Action/src/main/java/";
		String rootDir = "E:\\workspace_eclipse_luna\\demo\\target\\classes\\";
		// 创建两个不同的自定义类加载器实例
		FileClassLoader loader1 = new FileClassLoader(rootDir);
		FileClassLoader loader2 = new FileClassLoader(rootDir);
//		// 通过findClass创建类的Class对象
//		Class<?> object1 = loader1.findClass("com.wxsoft.java.classload.demo.DemoObj");
//		Class<?> object2 = loader2.findClass("com.wxsoft.java.classload.demo.DemoObj");
//
//		System.out.println("findClass->obj1:" + object1.hashCode());
//		System.out.println("findClass->obj2:" + object2.hashCode());

		/**
		 * 直接调用findClass方法输出结果: findClass->obj1:723074861
		 * findClass->obj2:895328852 生成不同的实例
		 */
		
		//直接调用父类的loadClass()方法
		Class<?> obj1 =loader1.loadClass("com.wxsoft.java.classload.demo.DemoObj");
		Class<?> obj2 =loader2.loadClass("com.wxsoft.java.classload.demo.DemoObj");

		//不同实例对象的自定义类加载器
		System.out.println("loadClass->obj1:"+obj1.hashCode());
		System.out.println("loadClass->obj2:"+obj2.hashCode());
		//系统类加载器 
		System.out.println("Class->obj3:"+DemoObj.class.hashCode());
		/**
		* 直接调用loadClass方法的输出结果,注意并没有重写loadClass方法
		* loadClass->obj1:1872034366
		  loadClass->obj2:1872034366
		  Class->    obj3:1872034366
		  都是同一个实例
		*/
	}
}
